package handler

import (
	"github.com/openai/openai-go/v3"
)

// ChatCompletionRequest represents a chat completion request
//
// refer to openai.ChatCompletionNewParams in
// https://github.com/openai/openai-go/blob/main/chatcompletion.go#L2902
type ChatCompletionRequest struct {
	Model    string                                   `json:"model"`
	Messages []openai.ChatCompletionMessageParamUnion `json:"messages"`
	// Controls which (if any) tool is called by the model. `none` means the model will
	// not call any tool and instead generates a message. `auto` means the model can
	// pick between generating a message or calling one or more tools. `required` means
	// the model must call one or more tools. Specifying a particular tool via
	// `{"type": "function", "function": {"name": "my_function"}}` forces the model to
	// call that tool.
	//
	// `none` is the default when no tools are present. `auto` is the default if tools
	// are present.
	ToolChoice openai.ChatCompletionToolChoiceOptionUnionParam `json:"tool_choice,omitzero"`
	// A list of tools the model may call. You can provide either
	// [custom tools](https://platform.openai.com/docs/guides/function-calling#custom-tools)
	// or [function tools](https://platform.openai.com/docs/guides/function-calling).
	Tools         []openai.ChatCompletionToolUnionParam `json:"tools,omitzero"`
	Temperature   float64                               `json:"temperature,omitempty"`
	MaxTokens     int                                   `json:"max_tokens,omitempty"`
	Stream        bool                                  `json:"stream,omitempty"`
	StreamOptions *StreamOptions                        `json:"stream_options,omitempty"`
}

// ChatMessage represents a chat message
type ChatMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
	// The tool calls generated by the model, such as function calls.
	ToolCalls []openai.ChatCompletionMessageToolCallUnionParam `json:"tool_calls,omitzero"`
	// Tool call that this message is responding to.
	ToolCallID string `json:"tool_call_id,omitzero"`
}

type StreamOptions struct {
	IncludeUsage bool `json:"include_usage,omitempty"`
}

// ChatCompletionResponse represents a chat completion response
type ChatCompletionResponse struct {
	ID      string `json:"id"`
	Object  string `json:"object"`
	Created int64  `json:"created"`
	Model   string `json:"model"`
	Choices []struct {
		Index        int         `json:"index"`
		Message      ChatMessage `json:"message"`
		FinishReason string      `json:"finish_reason"`
	} `json:"choices"`
	Usage struct {
		PromptTokens     int `json:"prompt_tokens"`
		CompletionTokens int `json:"completion_tokens"`
		TotalTokens      int `json:"total_tokens"`
	} `json:"usage"`
}

// ChatMessageHistoryResponse represents the chat message history response format
type ChatMessageHistoryResponse struct {
	Messages []ChatMessage `json:"messages"`
}

// EmbeddingRequest represents an embedding request structure
type EmbeddingRequest struct {
	Input          string `json:"input"`           // Input text content
	Model          string `json:"model"`           // Model name used (e.g., "text-embedding-ada-002")
	EncodingFormat string `json:"encoding_format"` // Encoding format (e.g., "float")
}
